
 <!--  主菜单-->
<?php 
	$this->load->view('_header');
?>


<script type="text/javascript" >
$(document).ready(function(){
	// 参考示例:  http://www.cnblogs.com/yuzhongwusan/archive/2009/02/27/1399264.html
	  // 全选
	  $("#btSelectAll").click(function(){
		 	 	//alert("Success: btSelectAll");
				$("input[name='SelectBoxInFlexiGrid']:visible").attr("checked","true");
				$("input[name='SelectBoxInFlexiGrid']:hidden").removeAttr("checked");
				var text="已选中 [ "+$("input[name='SelectBoxInFlexiGrid']:checked").length+" ] 条记录."
				setStatusInfo(text);
				checkAllLines($("#flex_DataGrid"));
				//alert("sadf");
	  });


	  // 取消选择
	  $("#btSelectNone").click(function(){
		  $("input[name='SelectBoxInFlexiGrid']:visible").removeAttr("checked");
		  $("input[name='SelectBoxInFlexiGrid']:hidden").removeAttr("checked");
			var text="全部取消选择."
			setStatusInfo(text);
			checkAllLines($("#flex_DataGrid"));		
	  });

	  // 反选
	  $("#btSelectInverse").click(function(){
		   $("input[name='SelectBoxInFlexiGrid']:visible").each( function(){
				 if($(this).attr("checked"))
				   {
				    $(this).removeAttr("checked");
				   }
				   else
				   {
				    $(this).attr("checked",'true');
				    
				   }
				   
				}
			
			);
		   $("input[name='SelectBoxInFlexiGrid']:hidden").removeAttr("checked");
			var text="已选中 [ "+$("input[name='SelectBoxInFlexiGrid']:checked").length+" ] 条记录."
			setStatusInfo(text);
			checkAllLines($("#flex_DataGrid"));		
	  });


		// 前一半
	  $("#btSelectFirstHalf").click(function(){
			var $count=$("input[name='SelectBoxInFlexiGrid']:visible").length;
			//alert($("input[name='SelectBoxInFlexiGrid']:visible").length);

			var $i=1;
			$("input[name='SelectBoxInFlexiGrid']:visible").each( function(){

				if($i>$count/2)
				{
					$(this).removeAttr("checked");
				}else{
					$(this).attr("checked",'true');
				}
				$i=$i+1;
				
				}
			
			);
			$("input[name='SelectBoxInFlexiGrid']:hidden").removeAttr("checked");
			var text="已选中 [ "+$("input[name='SelectBoxInFlexiGrid']:checked").length+" ] 条记录."
			setStatusInfo(text);
			checkAllLines($("#flex_DataGrid"));
			
	  });



		// 选择区间 
	  $("#btSelectSection").click(function(){
			var $count=$("input[name='SelectBoxInFlexiGrid']:visible").length;
			var $i=1;
			var $first=1;
			var $last=$count;
	
			$("input[name='SelectBoxInFlexiGrid']:visible").each( function(){
				if($(this).attr("checked")){
					$first=$i;
					$i=$i+1;
					return false;
					}
 				$i=$i+1;
				}
			);

			$i=1;
			$("input[name='SelectBoxInFlexiGrid']:visible").each( function(){
				if($(this).attr("checked")){
					$last=$i;
					}
 				$i=$i+1;
				}
			);

			if($first==$last)
				$last=$count;

			$i=1;
			$("input[name='SelectBoxInFlexiGrid']:visible").each( function(){
 				if(($i>=$first)&&($i<=$last)){
 					$(this).attr("checked",'true');
 	 				}
	 			$i+=1;
				}
			);

			// ------------------------
			$("input[name='SelectBoxInFlexiGrid']:hidden").removeAttr("checked");
			var text="已选中 [ "+$("input[name='SelectBoxInFlexiGrid']:checked").length+" ] 条记录."
			setStatusInfo(text);
			checkAllLines($("#flex_DataGrid"));		
			
	  });


		//--删除所选记录 
	  $("#delRecord_1").click(function(){
		//alert("<?php echo base_url()?>user/userList/delRows");
		//alert("删除记录:" + $("input[name='SelectBoxInFlexiGrid']:checked").length);
	     $.ajax({
	         url:"<?php echo base_url()?>user/userList/delRows",
	         type: 'POST',         //数据发送方式
	         dataType: 'json',     //接受数据格式
	         data:{"1":"Isdf"},         //要传递的数据
	         success:function(data){
				alert("Success["+ data+"]");
		     }, //回传函数(这里是函数名)
	     	 error:function(){
			     	alert('ERROR');
			 }
	       });

	    // $("tr:even").fadeOut();
	     checkAllLines($("#flex_DataGrid"));		
	       
	  });


		
	//-- 文本框实时搜索
	  $("#m_searchBox").keyup(function(e){
		  var code = (e.keyCode ? e.keyCode : e.which);
		  //alert(code);
			if(code==13)
			{
				$("#m_searchSubmitButton").trigger("click");
			}
			//alert(event.keyCode);
		  });
	  
	  $("#m_searchWholeWord").click(function(){
		  // 手动触发按钮点击的事件
		  $("#m_searchSubmitButton").trigger("click");
		  });

	  
	//--搜索记录 
 	 $("#m_searchSubmitButton").click(function(){
			var keyWord=$("#m_searchBox").attr("Value");
			keyWord=document.getElementById("m_searchBox").value;
 
			//alert($(this).children().eq(2).text()); // 某个tr里的第2个单元格的内容
			 $("input[name='SelectBoxInFlexiGrid']").each(function(){
				$(this).show();
				 });
			 
			// 如果keyWord="",显示所有
		  	if(!keyWord) {
				  $("tr").each(function(){
						$(this).fadeIn();
						if($('input',$(this).children()).attr("name") == "SelectBoxInFlexiGrid"){
						 	$('input',$(this).children()).show();}
						});
				  return false;
				  }//if
			$("tr").each(function(){
				$(this).hide();
				if($('input',$(this).children()).attr("name") == "SelectBoxInFlexiGrid"){
					 $('input',$(this).children()).hide();}
				});

//			var grid="#flex_DataGrid";
//			
//			$('tbody tr',grid.bDiv).each(function(){
//				if($('input',$(this).children()).attr("name") == "SelectBoxInFlexiGrid"){
//					 $('input',$(this).children()).hide();
//					}
//		  		
//			 });

			// 显示所有匹配的记录, 包括非全字匹配
			$("tr:first").fadeIn();
			$("tr:contains("+keyWord +")").each(function(){
					$(this).fadeIn();
					if($('input',$(this).children()).attr("name") == "SelectBoxInFlexiGrid"){
					 	$('input',$(this).children()).show();}
					
				});

			if(!$("#m_searchWholeWord").attr("checked")){
				$("tr:contains("+keyWord +")").each(function(){
					var exist=false;
					 $(this).children().each(function(){ // firefox 没有 children 等函数 
						    var cur=$(this).text();
						    cur = cur ? cur : "";
							if(cur.indexOf(keyWord)>=0){
								exist=true;
								return false;
								}
						 });
					if(!exist){
						$(this).hide();
						if($('input',$(this).children()).attr("name") == "SelectBoxInFlexiGrid"){
							 $('input',$(this).children()).hide();}
						}
					});

			}else{
				$("tr:contains("+keyWord +")").each(function(){
					var exist=false;
					 $(this).children().each(function(){ // firefox 没有 children 等函数 
						    var cur=$(this).text();
						    //cur = cur ? cur : "";
							if(cur==keyWord){
								exist=true;
								return false;
								}
						 });
					if(!exist){
						$(this).hide();
						if($('input',$(this).children()).attr("name") == "SelectBoxInFlexiGrid"){
							 $('input',$(this).children()).hide();}
						}
					
					});

			}

			$("input[name='SelectBoxInFlexiGrid']:hidden").removeAttr("checked");
			//alert($("input[name='SelectBoxInFlexiGrid']:hidden").length);
			var text="已选中 [ "+$("input[name='SelectBoxInFlexiGrid']:checked").length+" ] 条记录."
			setStatusInfo(text);	

			checkAllLines($("#flex_DataGrid"));		
 	 	 });// 搜索记录
 	 //-------------------------------


	  
});// 主函数体 



// 各种选择操作的函数,因为select的option没有click事件,所以只能这样实现
function selectRecords(){

	if(document.getElementById("m_selectMenu").options.selectedIndex==0){return false;}
	var optionValue = document.getElementById("m_selectMenu").options[document.getElementById("m_selectMenu").options.selectedIndex].id;
	//alert(optionValue);
	$("#"+optionValue).trigger("click");

	//select选项恢复重置
	document.getElementById("m_selectMenu").options.selectedIndex=0;
}

// 状态栏信息更新
function setStatusInfo(info){

	var tableName = document.getElementById("m_selectTable").options[document.getElementById("m_selectTable").options.selectedIndex].value;
 
	info = info ? info : "当前无操作";
	info = "[ "+tableName +" ]: "+ info;
	$("#m_statusInformation").html(info);
	setTitleofFlexi(info,"#flex_DataGrid");
}


// 选择不同的表格            -订单,用户,餐馆等等 
function selectTableChanged(){

	if(document.getElementById("m_selectTable").options.selectedIndex==0){return false;}
	var optionValue = document.getElementById("m_selectTable").options[document.getElementById("m_selectTable").options.selectedIndex].value;
	//var optionText = document.getElementById("m_selectTable").options[document.getElementById("m_selectTable").options.selectedIndex].innerHTML;
	if(optionValue != "orderdetail"){
		$("#m_selectTimeFilterForm").fadeOut();
		$("#m_selectOtherOperationForm").fadeOut();
		$("#m_changeOrderStatusForm").fadeOut();
		
	}else{
		$("#m_selectTimeFilterForm").fadeIn();
		$("#m_selectOtherOperationForm").fadeIn();
		$("#m_changeOrderStatusForm").fadeIn();
	}
	//$("#"+optionID).trigger("click");
	$("#m_selectTable").trigger("click");

	//select选项恢复重置
	//document.getElementById("m_selectTable").options.selectedIndex=0;
}


// 日期的格式化函数
Date.prototype.format = function(format){
    var o =
    {
        "M+" : this.getMonth()+1, //month
        "d+" : this.getDate(),    //day
        "h+" : this.getHours(),   //hour
        "m+" : this.getMinutes(), //minute
        "s+" : this.getSeconds(), //second
        "q+" : Math.floor((this.getMonth()+3)/3),  //quarter
        "S" : this.getMilliseconds(), //millisecond
        "w" : this.getDay()
    }
    if(/(y+)/.test(format))
    format=format.replace(RegExp.$1,(this.getFullYear()+"").substr(4 - RegExp.$1.length));
    for(var k in o)
    if(new RegExp("("+ k +")").test(format))
    format = format.replace(RegExp.$1,RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length));
    return format;
}


// 选择时间区间 
function timeFilterChanged(){

	//if(document.getElementById("m_selectTimeFilter").options.selectedIndex==0){return false;}
	var optionID = document.getElementById("m_selectTimeFilter").options[document.getElementById("m_selectTimeFilter").options.selectedIndex].id;
	var optionIndex = document.getElementById("m_selectTimeFilter").options.selectedIndex;
	//var optionText = document.getElementById("m_selectTimeFilter").options[document.getElementById("m_selectTimeFilter").options.selectedIndex].innerHTML;
	//alert(optionText);
	$("#"+optionID).trigger("click");
	var nowTime = new Date();
	var startTime = new Date();
	var hastime = 1;
	if(optionIndex == 1){//当天 
		startTime.setHours(0);
		startTime.setMinutes(0);
		startTime.setSeconds(0);
		}
	if(optionIndex == 2){//最近两天 
		startTime.setHours(0);
		startTime.setMinutes(0);
		startTime.setSeconds(0);
		startTime.setDate(startTime.getDate()-1);
		}
	if(optionIndex == 3){//最近一周
		startTime.setHours(0);
		startTime.setMinutes(0);
		startTime.setSeconds(0);
		startTime.setDate(startTime.getDate()-7);
		}
	if(optionIndex == 4){//最近一月
		startTime.setHours(0);
		startTime.setMinutes(0);
		startTime.setSeconds(0);
		startTime.setDate(startTime.getDate()-30);
		}
	if(optionIndex == 5){//最近一年
		startTime.setHours(0);
		startTime.setMinutes(0);
		startTime.setSeconds(0);
		startTime.setDate(startTime.getDate()-365);
		}
	if(optionIndex == 6 || optionIndex == 0){//所有
		startTime.setFullYear(1980);
		hastime = 0;
		}

	var stime = startTime.format("yyyy-MM-dd hh:mm:ss");
	var etime = nowTime.format("yyyy-MM-dd hh:mm:ss");
	//alert(timestr);
	
	// 更新表格内容
	var flexigrid_p = { 
			timeFlag:hastime,
			tStart: stime,
			tEnd: etime
			 };
	$("#flex_DataGrid").flexOptions(flexigrid_p);
	$("#flex_DataGrid").flexReload(flexigrid_p);
	
}



// 订单状态过滤
function otherOperationChanged(){

	//if(document.getElementById("m_selectOtherOperation").options.selectedIndex==0){return false;}
	var optionID = document.getElementById("m_selectOtherOperation").options[document.getElementById("m_selectOtherOperation").options.selectedIndex].id;
	var optionIndex = document.getElementById("m_selectOtherOperation").options.selectedIndex;
	//var optionText = document.getElementById("m_selectTimeFilter").options[document.getElementById("m_selectOtherOperation").options.selectedIndex].innerHTML;
	//alert(optionText);
	$("#"+optionID).trigger("click");

	var status = "";
	var statusFlag = 1;
	if(optionIndex==1){
		status = "accept";
		}
	if(optionIndex==2){
		status = "pending";
		}
	if(optionIndex==3){
		status = "reject";
		}
	if(optionIndex==4 || optionIndex==0){
		status = "";
		statusFlag = 0;
		}
 
	// 更新表格内容
	var flexigrid_p = { 
			orderStatus:status,
			orderStatusFlag:statusFlag
			 };
	$("#flex_DataGrid").flexOptions(flexigrid_p);
	$("#flex_DataGrid").flexReload(flexigrid_p);
	//select选项恢复重置
	//document.getElementById("m_selectOtherOperation").options.selectedIndex=0;
}

//修改订单状态
function changeOrderStatusRecords(){
 
	if(document.getElementById("m_changeOrderStatus").options.selectedIndex==0){return false;}
	var optionID = document.getElementById("m_changeOrderStatus").options[document.getElementById("m_changeOrderStatus").options.selectedIndex].id;
	var optionIndex = document.getElementById("m_changeOrderStatus").options.selectedIndex;
	var status = "123456";
	if(optionIndex==1){
		status="accept";
	}
	if(optionIndex==2){
		status="pending";
	}
	if(optionIndex==3){
		status="reject";
	}
	grid = "#flex_DataGrid";
	 
    if($('.trSelected',grid).length>0){
    	if(confirm('操作提醒: 修改 ' + $('.trSelected',grid).length + ' 条记录为: '+status+" ?")){
         var items = $('.trSelected',grid);
         var itemlist ='';
     	for(i=0;i<items.length;i++){
				itemlist+= items[i].id.substr(3)+",";
			}
	 
    	var param = [
					 { name : 'items', value :itemlist }
					 ,{ name : 'tableName', value : "orderdetail" }
					 ,{ name : 'status', value : status }
					 ];
    	$.ajax({
			   type: "POST",
			   dataType: "json",
			   url: "<?php echo base_url()?>user/userList/changeOrderStatus",
			   data: param,
			   success: function(data){
			   $("#flex_DataGrid").flexReload();
			   }
			 });
    	}// confirm
    }

	//select选项恢复重置
 
	document.getElementById("m_changeOrderStatus").options.selectedIndex = 0;
}


</script>





<div style="float:left; margin: 10px auto; padding:10 10px;width:200%; background-color:#D3D3D3;"> 

 
 <?php 
	$this->load->view('jQselectMenu');
?>

 
<!-- 从数据库读取数据并生成一个表格 -->
<?php 
	//$this->load->view('genTableFromSQL',$query);
?>

<?php 
	$this->load->view('genTableFromFlexigrid');
?>

 
</div> 


<?php $this->load->view('_footer');?>
















